<?php
	defined('_JEXEC') or die('Restricted access');
	//echo "ciao<br>";
	//print_r($arguments[6]);
	$a_query_parameter = $arguments[0];
	$a_current_field = $arguments[1];
	$a_current_field_no = $arguments[2];
	$a_fields_count = $arguments[3];
	$a_current_row_no = $arguments[4];
	$a_rows_count  = $arguments[5];
	$a_sender = $arguments[6];
	$local_field_name = $this->get_db_field_name($a_current_field);
	//echo "local_field_name: $local_field_name<br>";
    
			global $g_strings_utility_namespace;
			//echo "a_current_field->type: $a_current_field->type<br>";
			$l_value = $a_query_parameter->sql_values[$a_current_field_no];
			if (t_query_parameter::get_field_type($a_current_field->type) == 'datetime')
				$l_value = $g_strings_utility_namespace->get_ambient_datetime_fromat_from_mysql_datetime_value($a_query_parameter->sql_values[$a_current_field_no]);
			else if (t_query_parameter::get_field_type($a_current_field->type) == 'date')
				$l_value = $g_strings_utility_namespace->get_ambient_datetime_fromat_from_mysql_date_value($a_query_parameter->sql_values[$a_current_field_no]);
			else if (t_query_parameter::get_field_type($a_current_field->type) == 'time')
				$l_value = $g_strings_utility_namespace->get_ambient_datetime_fromat_from_mysql_time_value($a_query_parameter->sql_values[$a_current_field_no]);				
			//echo "a_query_parameter->sql_values[$a_current_field_no]: ". $a_query_parameter->sql_values[$a_current_field_no] ." - l_value: $l_value<br>";
//			$local_is_main_table = ($a_query_parameter->main_table_name == t_query_parameter::prepare_table_name($a_current_field->table));
			$local_result = '';
			$local_new_row = '';
			$local_special_column = $this->special_columns_array[$a_current_field_no];
			if ((($a_current_row_no == 0) || ($a_current_row_no == -1)) && ($a_current_field_no == 0))
			{
				$local_result = "<tbody>";
			}
			if ($a_current_row_no >= 0)
			{
				//echo "a_current_row_no:$a_current_row_no<br>";
				$local_row_name = $this->get_tag_name(t_field_grid::tag_prefix_row,array($a_current_row_no));
				if ($a_current_field_no == 0)
				{
					$local_result .= "<tr id=\"". $local_row_name ."\">".
						"<td><a><image id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_message,array($a_current_row_no)) ."\" class=\"".$this->get_tag_name(t_field_grid::style_name_none,array($this->name))."\"></image></a></td>";
				//}
				//echo "a_current_field->table:". $a_current_field->table."<br>";
               // if (($a_current_field->primary_key == 1) /*&& ($local_is_main_table)*/)
				//{
					$local_result .= $this->get_event_html_body_script(t_base_field::field_event_type_on_selected,$a_query_parameter,$a_current_field_no,$a_current_row_no);
					
					$local_result .= $this->get_event_html_body_script(t_base_field::field_event_type_on_edit,$a_query_parameter,$a_current_field_no,$a_current_row_no);
					
					$local_result .= $this->get_event_html_body_script(t_base_field::field_event_type_on_cancel,$a_query_parameter,$a_current_field_no,$a_current_row_no);
					
					$local_result .= $this->get_event_html_body_script(t_base_field::field_event_type_on_save,$a_query_parameter,$a_current_field_no,$a_current_row_no);
					
					$local_result .= $this->get_event_html_body_script(t_base_field::field_event_type_on_insert,$a_query_parameter,$a_current_field_no,$a_current_row_no);
					
					$local_result .= $this->get_event_html_body_script(t_base_field::field_event_type_on_delete,$a_query_parameter,$a_current_field_no,$a_current_row_no);		
				}
               
				$local_field = $this->parent_part->get_field($this->get_special_column_field('all',$local_field_name));
				
				if ((isset($local_field)) && (method_exists($local_field,'get_included_in_html_structure_no_edit_mode')))
				{
					$local_special_column = $this->special_columns_array[$a_current_field_no];
					$local_code = $local_field->get_included_in_html_structure_no_edit_mode($this->get_tag_name(t_field_grid::tag_prefix_value,array($a_current_row_no,$this->get_col_value($a_current_field_no))),
						$l_value,$a_query_parameter->sql_values[$local_special_column[t_field_grid::special_column_parameters_column_id_number]]);
					//echo $local_special_column[t_field_grid::special_column_parameters_column_id_number] ." - ".$a_query_parameter->sql_values[$local_special_column[t_field_grid::special_column_parameters_column_id_number]]."<br>";	
				}
				else
					$local_code = "<label id=\"". 
						$this->get_tag_name(t_field_grid::tag_prefix_value,array($a_current_row_no,$this->get_col_value($a_current_field_no))) .
						"\">".$l_value."</label>";
				//		
				$local_special_column = $this->special_columns_array[$a_current_field_no];
				if ((($a_current_field->name == 'sponsor_tipo_id') ) || 
				    ((isset($local_special_column)) && 
					($local_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_hidden_column)))
				{
					$local_style = 'style="display: none"';
				}    
				else
					$local_style = '';  
				$local_result .= "<td class=\"".$this->name."value_col ".$this->name.'_'.$a_current_field_no."_body\" $local_style id=\"" . 
					$this->get_tag_name(t_field_grid::tag_prefix_column,array($a_current_row_no,$a_current_field_no)) .
					"\" >$local_code";
				//
				if (isset($local_field))
				{

					//echo "IT IS SPECIAL COLUMN<br>";
					//echo "local_field->orgname: ".$local_field->orgname."<br>";
					//if ($this->is_description_field_required($local_special_column[t_field_grid::special_column_parameters_column_field_type]))
					$local_key_col_num = $local_special_column[t_field_grid::special_column_parameters_column_id_number];
					//else
					$local_col_num = $local_special_column[t_field_grid::special_column_parameters_column_description_number];
					//echo "local_col_num: $local_col_num - local_key_col_num: $local_key_col_num<br>"; 
					$local_result .= $local_field->get_included_in_html_structure(
						$this->get_special_column_field($a_current_row_no,$local_field_name),
						false,$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array($a_current_row_no,$this->get_col_value($local_key_col_num))),
						$a_current_row_no);
							
				}
				else
				{		
					$local_disabled = '';
					if (isset($local_special_column))
						$local_disabled = ' disabled="disabled" ';
					
					$local_result .="<textarea style=\"display: none\" $local_disabled id=\"". 
						$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array($a_current_row_no,$this->get_col_value($a_current_field_no))) .
						"\"></textarea></td>";
				}
				
				if ($a_current_field_no == ($a_fields_count-1))
				{
					$local_result .= "</tr>";
				}
			}	
			if (($a_current_row_no == ($a_rows_count-1)) && ($a_current_field_no == ($a_fields_count-1)))
			{
				
				if ($this->is_event_able(t_base_field::field_event_type_on_insert))
				{	
					//echo "PRIMA local_new_row - " .$local_new_row."<br>";	
					//echo "a_current_row_no: $a_current_row_no - a_current_field_no: $a_current_field_no<br>";  
                  //  $local_new_row .= "<tr id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row,array('ins')) ."\">".
					//	"<td id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_message,array('ins')) ."\" class=\"".$this->get_tag_name(t_field_grid::style_name_none,array($this->name))."\"></td>";
					$local_new_row .= "<tr id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row,array('ins')) ."\">".
						"<td><a><image id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_message,array('ins')) ."\" class=\"".$this->get_tag_name(t_field_grid::style_name_none,array($this->name))."\"></image></a></td>";
                        
                    //echo "local_new_row - $local_new_row<br>";	
					if ($this->is_event_able(t_base_field::field_event_type_on_selected))
                    {
                        
                        $local_new_row .= "<td align=\"center\" class=\"".$this->name."edit_col\"></td>";
                    }	
                    if ($this->is_event_able(t_base_field::field_event_type_on_edit))
                    {
                        $local_new_row .= "<td align=\"center\" class=\"".$this->name."edit_col\"></td>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_cancel))
                    {					
                        $local_new_row .= "<td align=\"center\" class=\"".$this->name."edit_col\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_cancel,array('ins')) ."\" href=\"#". $this->get_tag_name(t_field_grid::tag_prefix_row_insert,array('ins'))."\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_cancel,"event,'ins',true").">Cancel</span></a></td>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_save))
                    {
                        $local_new_row .= "<td align=\"center\" class=\"".$this->name."edit_col\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_save,array('ins')) ."\" href=\"#". $this->get_tag_name(t_field_grid::tag_prefix_row_insert,array('ins'))."\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_save,"event,'ins'").">Save</span></a></td>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_insert))
                    {
                        $local_new_row .= "<td align=\"center\" class=\"".$this->name."edit_col\"></td>";
                    }
                    if ($this->is_event_able(t_base_field::field_event_type_on_delete))
                    {
                        $local_new_row .= "<td align=\"center\" class=\"".$this->name."edit_col\"></td>";;
                    }					
					for ($i=0; $i <$a_fields_count; $i++)
                    {
						$local_special_column = $this->special_columns_array[$i]; 
						if (isset($local_special_column) && ($local_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_hidden_column))
						{
							$local_style = 'style="display: none"';
						}
						else
						{
							$local_style = '';
						}
						$local_new_row .= "<td class=\"".$this->name."value_col ".$this->name.'_'.$i."_body\" $local_style id=\"". 
							$this->get_tag_name(t_field_grid::tag_prefix_column,array('ins',$i)) .
							"\"><label id=\"". 
							$this->get_tag_name(t_field_grid::tag_prefix_value,array('ins',$this->get_col_value($i))) .
							"\"></label>";
						
						//echo "a_current_field_no: $a_current_field_no<br>";
						//echo "this->get_special_column_field('all',$a_current_field->orgname): " .$this->get_special_column_field('all',$a_current_field->orgname)."<br>";
						if (isset($local_special_column) && ($local_special_column[t_field_grid::special_column_parameters_column_description_number] == $i))
						{
							//echo "local_special_column[t_field_grid::special_column_parameters_column_description]: ".$local_special_column[t_field_grid::special_column_parameters_column_description]."<br>";
							$local_field = $this->parent_part->get_field($this->get_special_column_field('all',$local_special_column[t_field_grid::special_column_parameters_column_description]));
						}	
						else
							$local_field = null;
						if (isset($local_field))
						{
	   
							//echo "IT IS SPECIAL COLUMN i:$i<br>";
							//if ($this->is_description_field_required($local_special_column[t_field_grid::special_column_parameters_column_field_type]))
							$local_key_col_num = $local_special_column[t_field_grid::special_column_parameters_column_id_number];
							//else
							$local_col_num = $local_special_column[t_field_grid::special_column_parameters_column_description_number];
							$local_tags = $local_field->get_included_in_html_structure(
								$this->get_special_column_field('ins',$local_special_column[t_field_grid::special_column_parameters_column_description]),
								false,$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('ins',$this->get_col_value($local_key_col_num))),
								'ins');
							//echo "local_tags: $local_tags<br>";
							$local_new_row .= $local_tags;
						}
						else
						{
							$local_disabled = '';
							if (isset($local_special_column))
								$local_disabled = ' disabled="disabled" ';
					
							$local_new_row .= "<textarea $local_disabled id=\"". 
							    $this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('ins',$this->get_col_value($i))) .
								"\" style=\"display: none\"></textarea>";
						}    
						$local_new_row .= "</td>";                        
                    }    
					$local_result .= "$local_new_row</tbody>";
				}
				
					
			}		
			$local_return = $local_result;
		//print_r($local_return)
		
		
	
		
?>    